﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using HML.Design;

namespace HML
{
    /// <summary>
    /// 横向尺子控件
    /// </summary>
    [Description("横向尺子控件")]
    [DefaultProperty("MarkMainLineRate")]
    [TypeConverter(typeof(PropertyOrderConverter))]
    [Designer(typeof(HRulerDesigner))]
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(HRuler), "Controls.Ruler.Resources.HRuler.bmp")]
    public class HRuler : DpiControl, ISkinObject
    {
        #region 主题

        private SkinObjectXmlMetadata skinObjectXmlMetadata = null;
        /// <summary>
        /// 主题对象在主题文件信息
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual SkinObjectXmlMetadata SkinObjectXmlMetadata
        {
            get
            {
                if (this.skinObjectXmlMetadata == null)
                    this.skinObjectXmlMetadata = new SkinObjectXmlMetadata(Assembly.GetAssembly(typeof(HRuler)).GetName().Name, typeof(HRuler).Name);

                return this.skinObjectXmlMetadata;
            }
        }

        private SkinController skinController = null;
        /// <summary>
        /// 主题控制器
        /// </summary>
        [Description("主题控制器")]
        [Category("杂项")]
        [PropertyOrder(-360)]
        [DefaultValue(null)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinController SkinController
        {
            get { return this.skinController; }
            set
            {
                if (this.skinController == value)
                    return;

                if (this.skinController != null)
                    this.skinController.RemoveSkinObject(this);

                this.skinController = value;

                if (this.skinController != null)
                    this.skinController.AddSkinObject(this);
            }
        }

        private SkinEnabledState skinEnabled= SkinEnabledState.Auto;
        /// <summary>
        /// 主题是否启用
        /// </summary>
        [Description("主题是否启用")]
        [Category("杂项")]
        [PropertyOrder(-300)]
        [DefaultValue(SkinEnabledState.Auto)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinEnabledState SkinEnabled
        {
            get { return this.skinEnabled; }
            set
            {
                if (this.skinEnabled == value)
                    return;

                this.skinEnabled = value;
                this.OnSkinChanged();
            }
        }

        private SkinStyle skinStyle = SkinStyle.Normal;
        /// <summary>
        /// 主题风格
        /// </summary>
        [Description("主题风格")]
        [Category("杂项")]
        [PropertyOrder(-260)]
        [DefaultValue(SkinStyle.Normal)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinStyle SkinStyle
        {
            get { return this.skinStyle; }
            set
            {
                if (this.skinStyle == value)
                    return;

                this.skinStyle = value;
                this.OnSkinChanged();
            }
        }

        private StyleAppearanceObject stateAppearance;
        /// <summary>
        /// 风格外观
        /// </summary>
        [Description("风格外观")]
        [Category("杂项")]
        [PropertyOrder(-200)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public StyleAppearanceObject StyleAppearance
        {
            get
            {
                if (this.stateAppearance == null)
                    this.stateAppearance = new StyleAppearanceObject(this, null);
                return this.stateAppearance;
            }
        }

        /// <summary>
        /// 主题已更改
        /// </summary>
        public virtual void OnSkinChanged()
        {
            SkinManager.SyncSkinValueToProperty(this);
            this.Invalidate();
        }

        private ISkinObject followSkinObject = null;
        /// <summary>
        /// 主题设置跟随指定主题对象（自己的设置不再生效，提供给代码使用）
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Localizable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual ISkinObject FollowSkinObject
        {
            get { return this.followSkinObject; }
            set
            {
                if (this.followSkinObject == value)
                    return;

                this.followSkinObject = value;
                this.OnSkinChanged();
            }
        }

        public virtual bool GetSkinObjectSkinStateCore()
        {
            return SkinManager.GetSkinObjectSkinState(this.FollowSkinObject ?? this);
        }

        void ISkinObject.InitializeInvalidate()
        {
            throw new NotImplementedException();
        }

        void ISkinObject.Invalidate()
        {
            this.Invalidate();
        }

        #endregion

        #region 停用事件

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TabIndexChanged
        {
            add { base.TabIndexChanged += value; }
            remove { base.TabIndexChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TabStopChanged
        {
            add { base.TabStopChanged += value; }
            remove { base.TabStopChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event KeyEventHandler KeyDown
        {
            add { base.KeyDown += value; }
            remove { base.KeyDown -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event KeyEventHandler KeyUp
        {
            add { base.KeyUp += value; }
            remove { base.KeyUp -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event KeyPressEventHandler KeyPress
        {
            add { base.KeyPress += value; }
            remove { base.KeyPress -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event PreviewKeyDownEventHandler PreviewKeyDown
        {
            add { base.PreviewKeyDown += value; }
            remove { base.PreviewKeyDown -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler PaddingChanged
        {
            add { base.PaddingChanged += value; }
            remove { base.PaddingChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TextChanged
        {
            add { base.TextChanged += value; }
            remove { base.TextChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler RightToLeftChanged
        {
            add { base.RightToLeftChanged += value; }
            remove { base.RightToLeftChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ImeModeChanged
        {
            add { base.ImeModeChanged += value; }
            remove { base.ImeModeChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageChanged
        {
            add { base.BackgroundImageChanged += value; }
            remove { base.BackgroundImageChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageLayoutChanged
        {
            add { base.BackgroundImageLayoutChanged += value; }
            remove { base.BackgroundImageLayoutChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackColorChanged
        {
            add { base.BackColorChanged += value; }
            remove { base.BackColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ForeColorChanged
        {
            add { base.ForeColorChanged += value; }
            remove { base.ForeColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler Click
        {
            add { base.Click += value; }
            remove { base.Click -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler DoubleClick
        {
            add { base.DoubleClick += value; }
            remove { base.DoubleClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseClick
        {
            add { base.MouseClick += value; }
            remove { base.MouseClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseDoubleClick
        {
            add { base.MouseDoubleClick += value; }
            remove { base.MouseDoubleClick -= value; }
        }

        #endregion

        #region 新增属性

        private MarkObject mark;
        /// <summary>
        /// 刻度
        /// </summary>
        [Description("刻度")]
        [Category("杂项")]
        [PropertyOrder(-198)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public MarkObject Mark
        {
            get
            {
                if (this.mark == null)
                    this.mark = new MarkObject(this);
                return this.mark;
            }
        }

        private float zoomScaling = 1f;
        /// <summary>
        /// 尺子缩放比例（真实像素/显示像素）
        /// </summary>
        [Description("尺子缩放比例（真实像素/显示像素）")]
        [Category("杂项")]
        [PropertyOrder(-196)]
        [DefaultValue(1f)]
        public float ZoomScaling
        {
            get { return this.zoomScaling; }
            set
            {
                if (this.zoomScaling == value)
                    return;

                this.zoomScaling = value;
                this.Invalidate();
            }
        }

        #endregion

        #region 重写属性

        protected override Size DefaultSize
        {
            get { return new Size(160, 21); }
        }

        protected override Padding DefaultMargin
        {
            get { return new Padding(0); }
        }

        protected override Padding DefaultPadding
        {
            get { return new Padding(0); }
        }

        #endregion

        #region 停用属性

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new Size MaximumSize
        {
            get { return base.MaximumSize; }
            set { base.MaximumSize = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new Size MinimumSize
        {
            get { return base.MinimumSize; }
            set { base.MinimumSize = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new Padding Padding
        {
            get { return base.Padding; }
            set { base.Padding = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new int TabIndex
        {
            get { return base.TabIndex; }
            set { base.TabIndex = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new bool TabStop
        {
            get { return base.TabStop; }
            set { base.TabStop = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string Text
        {
            get { return base.Text; }
            set { base.Text = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override RightToLeft RightToLeft
        {
            get { return base.RightToLeft; }
            set { base.RightToLeft = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new ImeMode ImeMode
        {
            get { return base.ImeMode; }
            set { base.ImeMode = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Image BackgroundImage
        {
            get { return base.BackgroundImage; }
            set { base.BackgroundImage = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override ImageLayout BackgroundImageLayout
        {
            get { return base.BackgroundImageLayout; }
            set { base.BackgroundImageLayout = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color BackColor
        {
            get { return this.StyleAppearance.BackColor; }
            set { }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color ForeColor
        {
            get { return this.StyleAppearance.TextColor; }
            set { }
        }

        #endregion

        #region 字段

        /// <summary>
        /// 高亮线坐标（像素）
        /// </summary>
        private float markHighlightLinePosition = 0;

        /// <summary>
        /// 字体高度
        /// </summary>
        private int font_height = 0;

        #endregion

        public HRuler()
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.StandardClick, false);
            SetStyle(ControlStyles.StandardDoubleClick, false);
            SetStyle(ControlStyles.Selectable, false);

            this.TabStop = false;
            this.OnSkinChanged();
        }

        #region 重写

        protected override void OnScaleDpiChangedInitialize()
        {
            this.Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;

            Pen mainline_pen = new Pen(this.StyleAppearance.Mark.MainLineColor, 1);
            Pen minorline_pen = new Pen(this.StyleAppearance.Mark.MinorLineColor, 1);
            SolidBrush maintext_sb = new SolidBrush(this.StyleAppearance.TextColor);

            float scale_main_interval_pixel = (int)Math.Ceiling(this.Mark.MainLinePixels * this.ScaleDpi);//单位主刻度为多少个像素
            float scale_main_interval_value = scale_main_interval_pixel / this.ZoomScaling;//单位主刻度的刻度对应值大小
            if (scale_main_interval_value % this.Mark.MainLineRate != 0)
            {
                scale_main_interval_value += this.Mark.MainLineRate - (scale_main_interval_value % this.Mark.MainLineRate);
                scale_main_interval_pixel = scale_main_interval_value * scale_main_interval_pixel / (scale_main_interval_pixel / this.ZoomScaling);
            }

            int minor_count = 5; //单位主刻度分成多少个次刻度
            float scale_minor_interval_pixel = scale_main_interval_pixel / (float)minor_count;//单位刻度为多少个像素

            //基线
            g.DrawLine(mainline_pen, new Point(this.ClientRectangle.Left, this.ClientRectangle.Bottom - 1), new Point(this.ClientRectangle.Right, this.ClientRectangle.Bottom - 1));

            //正向刻度
            for (int i = 0; ; i++)
            {
                //主刻度
                float scale_current_main_x = this.Mark.MainLinePosition + i * scale_main_interval_pixel;
                g.DrawLine(mainline_pen, new PointF(scale_current_main_x, this.ClientRectangle.Y), new PointF(scale_current_main_x, this.ClientRectangle.Bottom - 1));

                //主刻度文本
                string current_main_str = ((int)(i * scale_main_interval_value)).ToString();
                g.DrawString(current_main_str, this.Font, maintext_sb, new PointF(scale_current_main_x + 2, this.ClientRectangle.Y + (int)(this.font_height / 3f)));

                //次刻度
                for (int k = 1; k < minor_count; k++)
                {
                    float scale_current_minor_x = scale_current_main_x + k * scale_minor_interval_pixel;
                    g.DrawLine(minorline_pen, new PointF(scale_current_minor_x, this.ClientRectangle.Bottom - this.font_height / 2), new PointF(scale_current_minor_x, this.ClientRectangle.Bottom - 2));
                }

                if (this.Mark.MainLinePosition + (i + 1) * scale_main_interval_pixel > this.ClientRectangle.Right)
                {
                    break;
                }
            }

            //反向刻度
            if (this.Mark.MainLinePosition > 0)
            {
                for (int i = 0; ; i++)
                {
                    //主刻度
                    float scale_current_main_x = this.Mark.MainLinePosition - i * scale_main_interval_pixel;
                    g.DrawLine(mainline_pen, new PointF(scale_current_main_x, this.ClientRectangle.Y), new PointF(scale_current_main_x, this.ClientRectangle.Bottom - 1));

                    //主刻度文本
                    string current_main_str = (this.Mark.MainTextSigned && i > 0 ? "-" : "") + ((int)(i * scale_main_interval_value)).ToString();
                    g.DrawString(current_main_str, this.Font, maintext_sb, new PointF(scale_current_main_x + 2, this.ClientRectangle.Y + (int)(this.font_height / 3f)));

                    //次刻度
                    for (int k = 1; k < minor_count; k++)
                    {
                        float scale_current_minor_x = scale_current_main_x - k * scale_minor_interval_pixel;
                        g.DrawLine(minorline_pen, new PointF(scale_current_minor_x, this.ClientRectangle.Bottom - this.font_height / 2), new PointF(scale_current_minor_x, this.ClientRectangle.Bottom - 2));
                    }

                    if (this.Mark.MainLinePosition - i * scale_main_interval_pixel < 0)
                    {
                        break;
                    }
                }
            }

            mainline_pen.Dispose();
            minorline_pen.Dispose();
            maintext_sb.Dispose();

            //高亮线
            if (this.Mark.HighlightLineVisible)
            {
                Pen highlightline_pen = new Pen(this.StyleAppearance.Mark.HighlightLineColor);
                g.DrawLine(highlightline_pen, new PointF(this.markHighlightLinePosition, this.ClientRectangle.Top), new PointF(this.markHighlightLinePosition, this.ClientRectangle.Bottom));
                highlightline_pen.Dispose();
            }
        }

        protected override void OnFontChanged(EventArgs e)
        {
            base.OnFontChanged(e);


            this.Height = this.GetControlAutoHeight();
        }

        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            height = this.GetControlAutoHeight();

            base.SetBoundsCore(x, y, width, height, specified);
        }

        #endregion

        #region 公开方法

        /// <summary>
        /// 设置高亮线坐标
        /// </summary>
        /// <param name="x">x轴（像素）</param>
        public void SetHighlightLinePosition(float x)
        {
            this.markHighlightLinePosition = x;
            this.Invalidate();
        }

        /// <summary>
        /// 设置高亮线坐标
        /// </summary>
        /// <param name="visible">是否显示高亮线</param>
        /// <param name="x">x轴（像素）</param>
        public void SetHighlightLinePosition(bool visible, float x)
        {
            this.Mark.HighlightLineVisible = visible;
            this.markHighlightLinePosition = x;
            this.Invalidate();
        }

        #endregion

        #region 私有方法

        /// <summary>
        /// 根据字体计算控件高度
        /// </summary>
        /// <returns></returns>
        private int GetControlAutoHeight()
        {
            NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);
            this.font_height = font_metrics.GetFontRealHeight();
            return (int)(this.font_height / 3f) + this.font_height + (int)(this.font_height / 3f) + this.font_height / 2;
        }

        #endregion

        #region 类

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class MarkObject
        {
            private HRuler owner = null;
            internal MarkObject(HRuler owner) { this.owner = owner; }

            #region 属性

            private float mainLineRate = 10f;
            /// <summary>
            /// 主刻度值只为该数的倍数
            /// </summary>
            [Description("主刻度值只为该数的倍数")]
            [PropertyOrder(-198)]
            [DefaultValue(10f)]
            public float MainLineRate
            {
                get { return this.mainLineRate; }
                set
                {
                    if (this.mainLineRate == value || value <= 0)
                        return;

                    this.mainLineRate = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private int mainLinePosition = 0;
            /// <summary>
            /// 零刻度线的开始坐标（像素）
            /// </summary>
            [Description("零刻度线的开始坐标（像素）")]
            [PropertyOrder(-196)]
            [DefaultValue(0)]
            public int MainLinePosition
            {
                get { return this.mainLinePosition; }
                set
                {
                    if (this.mainLinePosition == value)
                        return;

                    this.mainLinePosition = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private int mainLinePixels = 40;
            /// <summary>
            /// 单位主刻度预设多少个像素
            /// </summary>
            [Description("单位主刻度预设多少个像素")]
            [PropertyOrder(-194)]
            [DefaultValue(40)]
            public int MainLinePixels
            {
                get { return this.mainLinePixels; }
                set
                {
                    if (this.mainLinePixels == value || value <= 0)
                        return;

                    this.mainLinePixels = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private bool mainTextSigned = false;
            /// <summary>
            /// 主刻度文本是否带正负符号
            /// </summary>
            [Description("主刻度文本是否带正负符号")]
            [PropertyOrder(-190)]
            [DefaultValue(false)]
            public bool MainTextSigned
            {
                get { return this.mainTextSigned; }
                set
                {
                    if (this.mainTextSigned == value)
                        return;

                    this.mainTextSigned = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private bool highlightLineVisible = false;
            /// <summary>
            /// 是否显示高亮线
            /// </summary>
            [Description("是否显示高亮线")]
            [PropertyOrder(-182)]
            [DefaultValue(false)]
            public bool HighlightLineVisible
            {
                get { return this.highlightLineVisible; }
                set
                {
                    if (this.highlightLineVisible == value)
                        return;

                    this.highlightLineVisible = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            #endregion

        }

        #endregion

        #region 外观

        public class StyleAppearanceObject : AppearanceObjectBase
        {
            internal StyleAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

            #region 属性

            private Color skinBackColor = Color.Empty;
            private readonly Color defaultBackColor = SystemColors.Control;
            private Color backColor = Color.Empty;
            /// <summary>
            /// 背景颜色
            /// </summary>
            [Description("背景颜色")]
            [PropertyOrder(-195)]
            [SkinProperty(true, true)]
            public Color BackColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore() && this.skinBackColor != Color.Empty)
                    {
                        return this.skinBackColor;
                    }

                    if (this.backColor != Color.Empty)
                    {
                        return this.backColor;
                    }

                    if (((Control)this.owner).Parent != null)
                    {
                        return ((Control)this.owner).Parent.BackColor;
                    }

                    return this.defaultBackColor;
                }
                set
                {
                    if (this.backColor == value)
                        return;

                    this.backColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeBackColor()
            {
                return this.backColor != Color.Empty;
            }
            private void ResetBackColor()
            {
                this.backColor = Color.Empty;
                this.Invalidate();
            }

            private Color skinTextColor = Color.Empty;
            private readonly Color defaultTextColor = SystemColors.ControlText;
            private Color textColor = Color.Empty;
            /// <summary>
            /// 文本颜色
            /// </summary>
            [Description("文本颜色")]
            [PropertyOrder(-193)]
            [SkinProperty(true, true)]
            public Color TextColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore() && this.skinTextColor != Color.Empty)
                    {
                        return this.skinTextColor;
                    }

                    if (this.textColor != Color.Empty)
                    {
                        return this.textColor;
                    }

                    if (((Control)this.owner).Parent != null)
                    {
                        return ((Control)this.owner).Parent.ForeColor;
                    }

                    return this.defaultTextColor;
                }
                set
                {
                    if (this.textColor == value)
                        return;

                    this.textColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeTextColor()
            {
                return this.textColor != Color.Empty;
            }
            private void ResetTextColor()
            {
                this.textColor = Color.Empty;
                this.Invalidate();
            }

            private MarkAppearanceObject mark;
            /// <summary>
            /// 刻度
            /// </summary>
            [Description("刻度")]
            [PropertyOrder(-190)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public MarkAppearanceObject Mark
            {
                get
                {
                    if (this.mark == null)
                        this.mark = new MarkAppearanceObject(this.owner, this);
                    return this.mark;
                }
            }

            #endregion

            public class MarkAppearanceObject : AppearanceObjectBase
            {
                internal MarkAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private Color skinMainLineColor = Color.Empty;
                private readonly Color defaultMainLineColor = SystemColors.ControlText;
                private Color mainLineColor = Color.Empty;
                /// <summary>
                /// 主刻度线颜色
                /// </summary>
                [Description("主刻度线颜色")]
                [PropertyOrder(-186)]
                [SkinProperty(true, true)]
                public Color MainLineColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore() && this.skinMainLineColor != Color.Empty)
                        {
                            return this.skinMainLineColor;
                        }

                        if (this.mainLineColor != Color.Empty)
                        {
                            return this.mainLineColor;
                        }

                        if (((Control)this.owner).Parent != null)
                        {
                            return ((Control)this.owner).Parent.ForeColor;
                        }

                        return this.defaultMainLineColor;
                    }
                    set
                    {
                        if (this.mainLineColor == value)
                            return;

                        this.mainLineColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeMainLineColor()
                {
                    return this.mainLineColor != Color.Empty;
                }
                private void ResetMainLineColor()
                {
                    this.mainLineColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinMinorLineColor = Color.Empty;
                private readonly Color defaultMinorLineColor = SystemColors.ControlText;
                private Color minorLineColor = Color.Empty;
                /// <summary>
                /// 次刻度线颜色
                /// </summary>
                [Description("次刻度线颜色")]
                [PropertyOrder(-184)]
                [SkinProperty(true, true)]
                public Color MinorLineColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore() && this.skinMinorLineColor != Color.Empty)
                        {
                            return this.skinMinorLineColor;
                        }

                        if (this.minorLineColor != Color.Empty)
                        {
                            return this.minorLineColor;
                        }

                        if (((Control)this.owner).Parent != null)
                        {
                            return ((Control)this.owner).Parent.ForeColor;
                        }

                        return this.defaultMinorLineColor;
                    }
                    set
                    {
                        if (this.minorLineColor == value)
                            return;

                        this.minorLineColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeMinorLineColor()
                {
                    return this.minorLineColor != Color.Empty;
                }
                private void ResetMinorLineColor()
                {
                    this.minorLineColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinHighlightLineColor = Color.Empty;
                private readonly Color defaultHighlightLineColor = SystemColors.Highlight;
                private Color highlightLineColor = Color.Empty;
                /// <summary>
                /// 高亮线颜色
                /// </summary>
                [Description("高亮线颜色")]
                [PropertyOrder(-178)]
                [SkinProperty(true, false)]
                public Color HighlightLineColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinHighlightLineColor;
                        }

                        if (this.highlightLineColor != Color.Empty)
                        {
                            return this.highlightLineColor;
                        }

                        return this.defaultHighlightLineColor;
                    }
                    set
                    {
                        if (this.highlightLineColor == value)
                            return;

                        this.highlightLineColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeHighlightLineColor()
                {
                    return this.highlightLineColor != Color.Empty;
                }
                private void ResetHighlightLineColor()
                {
                    this.highlightLineColor = Color.Empty;
                    this.Invalidate();
                }

                #endregion

            }

        }

        #endregion

    }
}
